package com.xingkeduo.business.user.controller;

import com.xingkeduo.business.transformation.json.CraftsmanJobJTO;
import com.xingkeduo.business.transformation.json.CraftsmanServiceJTO;
import com.xingkeduo.business.transformation.json.CraftsmanSocialJTO;
import com.xingkeduo.business.transformation.json.PriceManagementDtoJTO;
import com.xingkeduo.business.user.domain.ServiceDomain;
import com.xingkeduo.pojo.dto.PriceManagementDto;
import com.xingkeduo.pojo.query.CraftsmanJobQO;
import com.xingkeduo.pojo.query.CraftsmanServiceQO;
import com.xingkeduo.pojo.query.CraftsmanSocialQO;
import com.xingkeduo.util.pojo.base.BaseController;
import com.xingkeduo.util.pojo.domain.Page;
import com.xingkeduo.util.pojo.domain.PageJTO;
import com.xingkeduo.util.tool.ReturnUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**调价管理
 * @Description:
 * @Author:gaozifeng
 * @Date 2019/5/13 15:00
 **/
//@CrossOrigin
@RestController
@RequestMapping("/craftsman/service/list")
public class CraftsmanServiceListController extends BaseController {

    @Autowired
    private ServiceDomain serviceDomain;

    @RequestMapping("/{body:.+}")
    public String getCraftsmanServiceList(@PathVariable String body, int page, int limit) {
        returnUtil = new ReturnUtil();
        try {
            CraftsmanServiceQO queryList = CraftsmanServiceJTO.createQueryList(body);
            CraftsmanJobQO craftsmanJobQO = CraftsmanJobJTO.createQueryForConditionCode(body);
            CraftsmanSocialQO craftsmanSocialQO = CraftsmanSocialJTO.createQueryForListByCode(body);
            Page<PriceManagementDto> pageDO = new Page<PriceManagementDto>(page, limit);
            return returnUtil.getSuccess(PageJTO.toJson(pageDO, PriceManagementDtoJTO.toJson(serviceDomain.getCraftsmanInfoForList(queryList, craftsmanJobQO, craftsmanSocialQO, pageDO))));
        } catch (Throwable t) {
            return dealException(t, returnUtil);
        }
    }
}
